﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ES_Project.Model;
using System.Data;
using System.Data.SqlClient;

using System.Collections;
using System.Web.Security;

using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Configuration;

using System.Text;
using MySql.Data;
using MySql.Data.MySqlClient;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Web;
using CrystalDecisions.Shared;
using CrystalDecisions.ReportSource;
namespace ES_Project.Pages
{
    public partial class WebForm18 : System.Web.UI.Page
    {
        string StrConn = WebConfigurationManager.ConnectionStrings["baseessystem"].ToString();
        MySqlCommand objCmd = new MySqlCommand();
        ReportDocument myRpt = new ReportDocument();

        protected void Page_Load(object sender, EventArgs e)

        {
            this.Label2.Text = (string)Session["passrun"];
            if (Label2.Text == "")
            {
                this.family_code.Text = Request.QueryString["family_code"];
                this.RegisDate.Text = Request.QueryString["register_date"];
                this.FamilyName.Text = Request.QueryString["family_name"];
                this.st_code.Text = Request.QueryString["st_code"];
            }
            if (Label2.Text == "passrun")
            {
                this.family_code.Text = (string)Session["family_code"];
                this.RegisDate.Text = (string)Session["register_date"];
                this.FamilyName.Text = (string)Session["family_name"];
                this.st_code.Text = (string)Session["st_code"];
            }
            if (family_code.Text != "")
            {
                Label1.Text = "รหัสครอบครัว :";
                MySqlConnection Conn = new MySqlConnection(StrConn);

                string sqlsm;


                sqlsm = "select * from student_mast where    family_code= '" + family_code.Text + "'  ";
                Conn.Open();
                MySqlDataAdapter da = new MySqlDataAdapter(sqlsm, Conn);
                DataSet ds = new DataSet();
                da.Fill(ds, "Student_Mast");
                GridView1.DataSource = ds.Tables["Student_Mast"];
                GridView1.DataBind();
            }
            else
            {

                Label1.Text = "";
                MySqlConnection Conn = new MySqlConnection(StrConn);

                string sqlsm;


                sqlsm = "select * from student_mast where   st_code='" + st_code.Text + "' ";
                MySqlDataAdapter da = new MySqlDataAdapter(sqlsm, Conn);
                DataSet ds = new DataSet();
                da.Fill(ds, "Student_Mast");
                GridView1.DataSource = ds.Tables["Student_Mast"];
                GridView1.DataBind();

            }

        }

       
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            
            HyperLink st_code = (HyperLink)(e.Row.FindControl("st_code"));
            if (st_code != null)
            {
                st_code.NavigateUrl = "#";
                st_code.Attributes.Add("Onclick", "openW('FamilySearchDataSubject.aspx?st_code=" + Convert.ToString(DataBinder.Eval(e.Row.DataItem, "st_code")).ToString() + "&register_date=" + Convert.ToString(DataBinder.Eval(e.Row.DataItem, "register_date")).ToString() + "&family_code=" + Convert.ToString(DataBinder.Eval(e.Row.DataItem, "family_code")).ToString() + "&st_id=" + Convert.ToString(DataBinder.Eval(e.Row.DataItem, "st_id")).ToString() + "');");
                //st_code.NavigateUrl = "FamilySearchDataSubject.aspx?st_code=" + Convert.ToString(DataBinder.Eval(e.Row.DataItem, "st_code")) + "&register_date=" + Convert.ToString(DataBinder.Eval(e.Row.DataItem, "register_date"));
          
            }
          
            HyperLink st_name = (HyperLink)(e.Row.FindControl("st_name"));
            if (st_name != null)
            {

                st_name.NavigateUrl = "#";
                st_name.Attributes.Add("Onclick", "openW('FamilySearchDataSubject.aspx?st_code=" + Convert.ToString(DataBinder.Eval(e.Row.DataItem, "st_code")).ToString() + "&register_date=" + Convert.ToString(DataBinder.Eval(e.Row.DataItem, "register_date")).ToString() + "&family_code=" + Convert.ToString(DataBinder.Eval(e.Row.DataItem, "family_code")).ToString() + "&st_id=" + Convert.ToString(DataBinder.Eval(e.Row.DataItem, "st_id")).ToString() + "');");

            }
            HyperLink register_date = (HyperLink)(e.Row.FindControl("register_date"));
            if (register_date != null)
            {

                register_date.NavigateUrl = "#";
                register_date.Attributes.Add("Onclick", "openW('FamilySearchDataSubject.aspx?st_code=" + Convert.ToString(DataBinder.Eval(e.Row.DataItem, "st_code")).ToString() + "&register_date=" + Convert.ToString(DataBinder.Eval(e.Row.DataItem, "register_date")).ToString() + "&family_code=" + Convert.ToString(DataBinder.Eval(e.Row.DataItem, "family_code")).ToString() + "&st_id=" + Convert.ToString(DataBinder.Eval(e.Row.DataItem, "st_id")).ToString() + "');");

            }
            HyperLink st_end_date = (HyperLink)(e.Row.FindControl("st_end_date"));
            if (st_end_date != null)
            {

                st_end_date.NavigateUrl = "#";
                st_end_date.Attributes.Add("Onclick", "openW('FamilySearchDataSubject.aspx?st_code=" + Convert.ToString(DataBinder.Eval(e.Row.DataItem, "st_code")).ToString() + "&register_date=" + Convert.ToString(DataBinder.Eval(e.Row.DataItem, "register_date")).ToString() + "&family_code=" + Convert.ToString(DataBinder.Eval(e.Row.DataItem, "family_code")).ToString() + "&st_id=" + Convert.ToString(DataBinder.Eval(e.Row.DataItem, "st_id")).ToString() + "');");

            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            myRpt.Load(Server.MapPath("~/report/receipt1.rpt"));
            Session["rpt"] = myRpt;

            Response.Redirect("~/Pages/Report.aspx");
            myRpt.Close(); 
        }
    }
}